using AdminApi.Domain;
using AdminApi.Repositories;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// 添加控制器支持
builder.Services.AddControllers();

// 配置数据库上下文
var connectionString = builder.Configuration.GetConnectionString("Mysql");
builder.Services.AddDbContext<AdminDbContext>(options =>
{
    // 制定mysql服务器版本
    var serverVersion = new MySqlServerVersion(new Version(8, 0, 34));
    options.UseMySql(connectionString, serverVersion);
});

// 注册泛型仓储
builder.Services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

// app.UseHttpsRedirection();

// 配置中间件
app.UseRouting();

app.MapControllers();

app.Run();